#include <iostream>
#include"Comment.hpp"

int main() {
    try {
        // 创建Mapper实例
        CommentMapper mapper("tcp://112.74.40.147:3306", "root", "Ahqjhqj73@you", "novel_db");
        
        // 1. 新增评论
        Comment newComment;
        newComment.content = "这是一本很棒的小说！";
        newComment.user_id = 1001;
        newComment.novel_id = 2002;
        newComment.comment_type = "review";
        newComment.status = NovelStatus::COMPLETED;
        newComment.novel_type = "fantasy";
        
        int commentId = mapper.insert(newComment);
        std::cout << "新评论ID: " << commentId << std::endl;
        
        // 2. 通过ID获取评论
        auto comment = mapper.getById(commentId);
        if (comment) {
            std::cout << "获取评论内容: " << comment->content << std::endl;
        }
        
        // 3. 更新评论
        if (comment) {
            comment->content = "更新后的评论内容";
            if (mapper.update(*comment)) {
                std::cout << "评论更新成功" << std::endl;
            }
        }
        
        // 4. 删除评论
        if (mapper.remove(commentId)) {
            std::cout << "评论删除成功" << std::endl;
        }
        
        // 5. 获取用户的所有评论
        auto userComments = mapper.getByUserId(1001);
        std::cout << "用户评论数量: " << userComments.size() << std::endl;
        
        // 6. 获取小说的所有评论
        auto novelComments = mapper.getByNovelId(2002);
        std::cout << "小说评论数量: " << novelComments.size() << std::endl;
        
    } catch (const std::exception& e) {
        std::cerr << "错误: " << e.what() << std::endl;
    }
    
    return 0;
}